package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.OutofstockEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.StringUtil;

/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */
//1,id,gilgamesh_product,t_outofstock,BIGINT UNSIGNED,binary,20,0,0
//            2,sku_code,gilgamesh_product,t_outofstock,VARCHAR,utf8mb4,30,0,0
//            3,createTime,gilgamesh_product,t_outofstock,DATETIME,binary,19,0,0
//            4,status,gilgamesh_product,t_outofstock,TINYINT,binary,1,0,0
public class OutofstockSql {
    public String listOutofstocks(OutofstockEntity outofstockEntity) {
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_outofstock");
        if (BeanUtil.isLogicalNull(outofstockEntity)) {
            return sb.toString();
        }
        int times = 0;
        if (outofstockEntity.getId() != null) {
            if (times == 0) {
                sb.append("where");
            } else if (times > 0) {
                sb.append("and");
            }
            times++;
            sb.append("id = #{id}");
        }
        if (StringUtil.isNotEmpty(outofstockEntity.getSkuCode())) {
            if (times == 0) {
                sb.append("where");
            } else if (times > 0) {
                sb.append("and");
            }
            times++;
            sb.append("sku_code = #{skuCode}");
        }
        if (outofstockEntity.getStatus() != null) {
            if (times == 0) {
                sb.append("where");
            } else if (times > 0) {
                sb.append("and");
            }
            times++;
            sb.append("status = #{status}");
        }
        if (outofstockEntity.getCreatetime() != null) {
            if (times == 0) {
                sb.append("where");
            } else if (times > 0) {
                sb.append("and");
            }
            times++;
            sb.append("create_time =#{createTime}");
        }
        return sb.toString();
    }


}
